package com.rtos.vo.process;

import com.rtos.model.process.Process;
import com.rtos.model.process.queue.BlockingQueue;
import com.rtos.model.process.queue.ReadyQueue;
import com.rtos.model.process.queue.RunningQueue;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

/**
 * @Author: biubiu0002
 * @Date: 2021-10-26 13:02
 **/
public class ProcessQueueVO {
    private static ObservableList<Process> runningQueue = RunningQueue.getList();
    private static ObservableList<Process> readyQueue = ReadyQueue.getList();
    private static ObservableList<Process> blockingQueue = BlockingQueue.getList();


    public static void setRunningQueueTableView(TableView<Process> tableView,
                                                TableColumn<Process, IntegerProperty> pid,
                                                TableColumn<Process, DoubleProperty> totalRunTime,
                                                TableColumn<Process, DoubleProperty> restRunTime,
                                                TableColumn<Process, DoubleProperty> lastRunTime,
                                                TableColumn<Process, StringProperty> occupyType){

        pid.setCellValueFactory(new PropertyValueFactory("pid"));
        totalRunTime.setCellValueFactory(new PropertyValueFactory("totalRunTime"));
        restRunTime.setCellValueFactory(new PropertyValueFactory("restRunTime"));
        lastRunTime.setCellValueFactory(new PropertyValueFactory("lastRunTime"));
        occupyType.setCellValueFactory(new PropertyValueFactory("deviceType"));
        tableView.setItems(runningQueue);

    }

    public static void setReadyQueueTableView(TableView<Process> tableView,
                                              TableColumn<Process, IntegerProperty> pid,
                                              TableColumn<Process, StringProperty> totalRunTime,
                                              TableColumn<Process, StringProperty> restRunTime,
                                              TableColumn<Process, StringProperty> lastRunTime,
                                              TableColumn<Process, StringProperty> occupyType){

        pid.setCellValueFactory(new PropertyValueFactory("pid"));
        totalRunTime.setCellValueFactory(new PropertyValueFactory("totalRunTime"));
        restRunTime.setCellValueFactory(new PropertyValueFactory("restRunTime"));
        lastRunTime.setCellValueFactory(new PropertyValueFactory("lastRunTime"));
        occupyType.setCellValueFactory(new PropertyValueFactory("deviceType"));
        tableView.setItems(readyQueue);
    }

    public static void setBlockingQueueTableView(TableView<Process> tableView,
                                                 TableColumn<Process,IntegerProperty> pid,
                                                 TableColumn<Process, StringProperty> totalRunTime,
                                                 TableColumn<Process, StringProperty> restRunTime,
                                                 TableColumn<Process, StringProperty> lastRunTime,
                                                 TableColumn<Process, StringProperty> occupyType,
                                                 TableColumn<Process, IntegerProperty> occupyTime){
        pid.setCellValueFactory(new PropertyValueFactory("pid"));
        totalRunTime.setCellValueFactory(new PropertyValueFactory("totalRunTime"));
        restRunTime.setCellValueFactory(new PropertyValueFactory("restRunTime"));
        lastRunTime.setCellValueFactory(new PropertyValueFactory("lastRunTime"));
        occupyType.setCellValueFactory(new PropertyValueFactory("deviceType"));
        occupyTime.setCellValueFactory(new PropertyValueFactory("blockingTime"));
        tableView.setItems(blockingQueue);

    }
}
